<style lang="less">
</style>
<template>
    <div class="search" >
        <Row >
            <Col>
                <Card>

                    <Row class="operation">
                        <Button @click="add" type="primary" v-if="this.typeCode == '1'" icon="md-add">新增</Button>
                        <!--<Button @click="edit" type="primary" v-if="this.typeCode == '1'" icon="md-add">编辑</Button>-->
                    </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom"
                               @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table">
                            <template slot-scope="{row, index }" slot="action">
                            </template>
                            <template slot-scope="{ row, index }" slot="openingBankProvince">
                                <span>{{getOpeningBankProvince(row.openingBankProvince)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="openingBankCity">
                                <span>{{getOpeningBankCity(row.openingBankCity)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="collectionType">
                                <span>{{setCollectionTypeTitle(row.collectionType)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="accountType">
                                <span>{{setAccountTypeTitle(row.accountType)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="accountAttribute">
                                <span>{{setAccountAttributeTitle(row.accountAttribute)}}</span>
                            </template>
                            <template slot-scope="{ row, index }" slot="receivingBank">
                                <span>{{setReceivingBankTitle(row.receivingBank)}}</span>
                            </template>

                            <template slot-scope="{ row,  }" slot="status">
                                <div v-if="row.status == '00'">
                                    <Tag color="success" size="default">启用</Tag>
                                </div>
                                <div v-if="row.status == '01'">
                                    <Tag color="warning" size="default">审核中</Tag>
                                </div>
                                <div v-if="row.status == '02'">
                                    <Tag color="default" size="default">草稿</Tag>
                                </div>
                                <div v-if="row.status == '03'">
                                    <Tag color="warning" size="default">退回</Tag>
                                </div>
                                <div v-if="row.status == '04'">
                                    <Tag color="error" size="default">拒绝</Tag>
                                </div>
                                <div v-if="row.status == '05'">
                                    <Tag color="error" size="default">停用</Tag>
                                </div>
                            </template>

                            <template slot-scope="{ row }" slot="action">
                                <span v-if="row.status=='02'">
                                    <Button type="error" size="small" @click="remove(row)">删除</Button>
                                </span>
                                <span v-if="row.status!='02'">
                                    <Button disabled type="error" size="small" @click="remove(row)">删除</Button>
                                </span>
                                <span v-if="row.status=='02'|| row.status=='05' || row.status=='03' ">
                                    <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">编辑</Button>
                                </span>
                                <span v-if="row.status!='02'&&row.status!='05'&& row.status!='03' ">
                                    <Button disabled style="margin-right:5px" type="primary" size="small" @click="edit(row)">编辑</Button>
                                </span>
                            </template>

                        </Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="accountForm.pageNumber" :total="total" :page-size="accountForm.pageSize"
                              @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]"
                              size="small" show-total show-elevator show-sizer>
                        </Page>
                    </Row>
                </Card>
            </Col>
        </Row>
        <Modal :title="modalTitle" v-model="channelModalVisible" :mask-closable='false' :width="1000" :styles="{top: '200px'}">
            <Form ref="channelForm" :model="channelForm" :label-width="120" :rules="channelFormValidate">
                <Row>
                    <Col span="8">
                        <FormItem label="账号属性" prop="accountAttribute">
                            <RadioGroup v-model="channelForm.accountAttribute"  >
                                <Radio :false-value="''"  :key="radio.id" :label="radio.value" :true-value="radio.value" v-bind:disabled="accountAttributeDisabled" v-for="(radio) in accountAttributeList">{{radio.title}} </Radio>
                            </RadioGroup>
                        </FormItem>
                    </Col>
                </Row>

                <Row>
                    <Col span="8">
                        <FormItem label="账号类型" prop="accountType">
                            <Select v-model="channelForm.accountType" placeholder="账户类型" class="w200">
                                <Option :value="item.value" v-for="(item,index) in accountTypeList" :key="index"> {{item.title}}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="收款类型" prop="collectionType">
                            <RadioGroup v-model="channelForm.collectionType" >
                                <Radio :false-value="''" :key="radio.id" :label="radio.value" :true-value="radio.value" v-for="(radio) in collectionTypeList">{{radio.title}}</Radio>
                            </RadioGroup>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="银行账户名称" prop="receivingName">
                            <Input v-model="channelForm.receivingName" class="w200"  placeholder="请输入"/>
                        </FormItem>
                    </Col>
                </Row>

                <Row>
                    <Col span="8">
                        <FormItem label="收款方账号" prop="receivingAccount">
                            <Input v-model="channelForm.receivingAccount" class="w200"  placeholder="请输入"/>
                        </FormItem>
                    </Col>

                    <Col span="8">
                        <FormItem label="银行名称" prop="receivingBank">
                            <Select v-model="channelForm.receivingBank" placeholder="银行名称" class="w200">
                                <Option :value="item.value" v-for="(item,index) in receivingBankList" :key="index"> {{item.title}}</Option>
                            </Select>
                        </FormItem>
                    </Col>

                    <Col span="8">
                        <FormItem label="开户行名称" prop="receivingSubBranch">
                            <Input v-model="channelForm.receivingSubBranch" class="w200"  placeholder="请输入"/>
                        </FormItem>
                    </Col>
                </Row>

                <Row>
                    <Col span="8">
                        <FormItem label="收款方电子联行号" prop="electronicBankNo">
                            <Input v-model="channelForm.electronicBankNo" class="w200"  placeholder="请输入"/>
                        </FormItem>
                    </Col>

                    <Col span="8">
                        <FormItem label="收款方电话" prop="receivingMobilePhone">
                            <Input v-model="channelForm.receivingMobilePhone" class="w200"  placeholder="请输入"/>
                        </FormItem>
                    </Col>

                    <Col span="8">
                        <FormItem label="收款方电子邮箱" prop="receivingMailAddress">
                            <Input v-model="channelForm.receivingMailAddress" maxlength="32" class="w200"  placeholder="请输入"/>
                        </FormItem>
                    </Col>
                </Row>

                <Row>
                    <Col span="8">
                        <FormItem label="开户行省市" prop="openingBankValue">
                            <Cascader :load-data="locationChange" :data="location" v-model="channelForm.openingBankValue" placeholder="下拉选择省市"  class="show_cascader_input" :clearable="false">
                            </Cascader>
                        </FormItem>
                    </Col>
                </Row>

                <Row>
                    <Row>
                        <Col span="16">
                            <FormItem label="备注" prop="receivingRemarks">
                                <Input v-model="channelForm.receivingRemarks" maxlength="100" class="w500" placeholder="请输入备注" type="textarea"/>
                            </FormItem>
                        </Col>
                    </Row>
                </Row>

            </Form>
            <div slot="footer">
                <Button type="text" @click="cancelAccount">取消</Button>
                <Button type="primary" :loading="submitLoading" @click="saveAccount">保存</Button>
            </div>
        </Modal>
        <Form ref="invoiceForm" :model="invoiceForm" :label-width="110" :rules="invoiceFormValidate" v-bind:disabled="this.typeCode == '0'" >
            <div class="common_br">
                <h2 class="common_title" >开票信息</h2>
                <div class="common_content" style="padding-left: 10%;" >
                    <Row>
                        <Col span="8">
                            <FormItem label="纳税人类型" prop="taxpayerType">
                                <Select v-model="invoiceForm.taxpayerType" placeholder="账户类型" class="w200">
                                    <Option value="1">个人</Option>
                                    <Option value="2">小规模纳税人</Option>
                                    <Option value="3">一般纳税人</Option>
                                </Select>
                            </FormItem>
                        </Col>

                        <Col span="8">
                            <FormItem label="纳税人识别号" prop="taxpayerIdNumber">
                                <Input v-model="invoiceForm.taxpayerIdNumber" maxlength="32" class="w200"  placeholder="请输入"/>
                            </FormItem>
                        </Col>

                        <Col span="8">
                            <FormItem label="联系电话" prop="invoiceTelNumber">
                                <Input v-model="invoiceForm.invoiceTelNumber" class="w200"  placeholder="请输入"/>
                            </FormItem>
                        </Col>
                    </Row>

                    <Row>
                        <Col span="8">
                            <FormItem label="发票地址" prop="invoiceAddress">
                                <Input v-model="invoiceForm.invoiceAddress" class="w200"  maxlength="150" placeholder="请输入"/>
                            </FormItem>
                        </Col>

                        <Col span="8">
                            <FormItem label="开户行" prop="openingBank">
                                <Input v-model="invoiceForm.openingBank" class="w200" maxlength="32"  placeholder="请输入"/>
                            </FormItem>
                        </Col>

                        <Col span="8">
                            <FormItem label="开户行账户" prop="bankAccount">
                                <Input v-model="invoiceForm.bankAccount" class="w200" maxlength="32"  placeholder="请输入"/>
                            </FormItem>
                        </Col>
                    </Row>
                    <Row>
                        <Col span="8">
                            <FormItem label="税率" prop="taxRate">
                                <InputNumber  :max="100" :min="0" v-model="invoiceForm.taxRate" class="w200"  placeholder="请输入"/>
                            </FormItem>
                        </Col>
                    </Row>

                </div>
            </div>
        </Form>
    </div>
</template>
<script>
    import vueEvent from "_p/afs-apply/assets/js/vueEvent.js"

    import {
        deleteAccount,
        savaInvoiceInfo,
        saveAccountInfo,
        updateAccountInfo,
        changeAccountStatus,
        getChannelBaseInfo,
        getListData,
      } from  "@/projects/afs-apply/api/car-dealer/dealer";

    import {getLocation} from "_p/afs-apply/api/apply-report/personal/common";

    import {getDictDataByType} from "_p/basic/api/admin/datadic";

    import PlaceCascade from "@/components/place-cascade";
    export default {
        name: "account-manage",
        components:{
            PlaceCascade,
        },
        data() {
            const validateMobile = (rule, value, callback) => {
                if((value == null || value == "" || value == undefined)){
                    callback();
                }
                    let regPone = null;
                    let mobile = /^1(3|4|5|6|7|8|9)\d{9}$/; //最新16手机正则
                    let tel = /^(0[0-9]{2,3}\-)([2-9][0-9]{4,7})+(\-[0-9]{1,4})?$/; //座机
                    if (value.charAt(0) == 0) {    // charAt查找第一个字符方法，用来判断输入的是座机还是手机号
                        regPone = tel;
                    } else {
                        regPone = mobile;
                    }

                    if (!regPone.test(value)) {
                        return callback(
                            new Error("联系电话格式有误(座机格式'区号-座机号码')")
                        );
                    }
                    callback();
            };
            const validateEmail = (rule, value, callback) => {
                if((value == null || value == "" || value == undefined)){
                    callback();
                }
                    if (value !== '') {
                        var reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                        if (!reg.test(value)) {
                            callback(new Error('请输入有效的邮箱'));
                        }
                    }
                    callback();

            };
            const validateAccount = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入有效的银行卡号'));
                } else {
                    if (value !== '') {
                        var reg = /^([1-9]{1})(\d{9,23})$/ ;
                        if (!reg.test(value)) {
                            callback(new Error('请输入有效的银行卡号'));
                        }
                    }
                    callback();
                }
            };
            const validateLinkNumber = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入有效的电子联行号'));
                } else {
                    if (value !== '') {
                        var reg = /^([1-9]{1})(\d{5,11})$/ ;
                        if (!reg.test(value)) {
                            callback(new Error('请输入有效的电子联行号'));
                        }
                    }
                    callback();
                }
            };


            return {
                //新车二手车权限
                newCarRole:"",
                oldCarRole:"",

                accountAttributeDisabled:true,
                loading: false,
                importLoading: false,
                loadingExport: true,
                selectCount: 0,
                typeCode:1,
                selectList: [],
                //省份翻译
                province:[],
                //城市翻译
                city:[],
                //收款类型字典翻译
                collectionTypeList:[],
                //账号类型字典翻译
                accountTypeList:[],
                receivingAccountFlag:true,
                accountForm: {
                    channelId:"",
                    pageNumber: 1,
                    pageSize: 10,
                },
                //开票信息
                invoiceForm:{
                    id:"",
                    taxpayerType:"",
                    taxpayerIdNumber:"",
                    invoiceTelNumber:"",
                    invoiceAddress:"",
                    openingBank:"",
                    bankAccount:"",
                    channelStatus:"",
                    taxRate:"",
                },

                location:[],
                selectDate: null,
                modalType: 0,
                channelModalVisible: false,
                modalTitle: "",
                receivingName:"",
                //银行数据
                receivingBankList:[],
                //账户属性
                accountAttributeList:[],
                channelForm: {
                    accountAttribute:"",
                    accountType:"",
                    collectionType:"",
                    receivingName:"",
                    receivingAccount:"",
                    receivingBank:"",
                    receivingSubBranch:"",
                    electronicBankNo:"",
                    receivingMobilePhone:"",
                    receivingMailAddress:"",
                    receivingRemarks:"",
                    openingBankValue:[],
                    pageNumber: 1,
                    pageSize: 10,
                    status:"02",
                },
                invoiceFormValidate:{
                   /* taxpayerType: [
                        { required: true, message: "纳税人类型不能为空", trigger: "blur"}
                    ],
                    taxpayerIdNumber: [
                        { required: true, message: "纳税人识别号不能为空", trigger: "blur" }
                    ],*/
                    invoiceTelNumber: [
                       // { required: true, message: "联系电话不能为空", trigger: "blur" },
                        {validator: validateMobile, trigger: "blur"}
                    ],
                    /*invoiceAddress: [
                        { required: true, message: "发票地址不能为空", trigger: "blur" }
                    ],
                    openingBank: [
                        { required: true, message: "开户行不能为空", trigger: "blur" }
                    ],
                    bankAccount: [
                        { required: true, message: "开户行账户不能为空", trigger: "blur" }
                    ],*/
                    taxRate: [
                       // { required: true, message: "税率不能为空", trigger: "blur" }
                    ],
                },
                channelFormValidate: {
                    accountAttribute: [
                        { required: true, message: "账户属性不能为空", trigger: "change"}
                    ],
                    accountType: [
                        { required: true, message: "账户类型不能为空", trigger: "change" }
                    ],
                    collectionType: [
                        { required: true, message: "收款类型不能为空", trigger: "change" }
                    ],
                    receivingName: [
                        { required: true, message: "银行账户名称不能为空", trigger: "blur" }
                    ],
                    receivingAccount: [
                        { required: true, message: "收款方账号不能为空", trigger: "blur" },
                        {validator: validateAccount, trigger: "blur"}
                    ],
                    receivingBank: [
                        { required: true, message: "银行名称不能为空", trigger: "blur" }
                    ],
                    receivingSubBranch: [
                        { required: true, message: "开户行名称不能为空", trigger: "blur" }
                    ],
                    openingBankValue:[
                        { required: true, type: 'array', message: '开户行不能为空', trigger: 'change' },
                    ],
                    electronicBankNo: [
                        { required: true, message: "收款方电子联行号不能为空", trigger: "blur" },
                        {validator: validateLinkNumber, trigger: "blur"}
                    ],
                    receivingMobilePhone: [
                        { required: true, message: "收款方电话不能为空", trigger: "blur" },
                        {validator: validateMobile, trigger: "blur"}
                    ],
                    receivingMailAddress: [
                        { required: false, message: "收款方电子邮箱不能为空", trigger: "blur" },
                        {validator: validateEmail, trigger: "blur"}
                    ],
                    defaultAccount: [
                        { required: true, message: "是否默认账号不能为空", trigger: "blur" }
                    ],
                    /*receivingRemarks: [
                        { required: true, message: "备注不能为空", trigger: "blur" }
                    ],*/
                },
                submitLoading: false,
                columns: [
                    {
                        type: 'index',
                        title:"序号",
                        minWidth: 80,
                        align: "center",
                        fixed: "left"

                    },
                    {
                        title: "银行账户名称",
                        key: "receivingName",
                        minWidth: 150
                    },
                    {
                        title: "银行名称",
                        key: "receivingBank",
                        minWidth: 155,
                        slot:"receivingBank",
                    },
                    {
                        title: "开户行名称",
                        key: "receivingSubBranch",
                        minWidth: 150
                    },
                    {
                        title: "收款方账号",
                        key: "receivingAccount",
                        minWidth: 150
                    },
                    {
                        title: "收款方电子联行号",
                        key: "electronicBankNo",
                        minWidth: 150
                    },
                    {
                        title: "账号属性",
                        key: "accountAttribute",
                        minWidth: 150,
                        slot:"accountAttribute"
                    },
                    {
                        title: "收款类型",
                        key: "collectionType",
                        minWidth: 150,
                        slot:"collectionType"
                    },

                    {
                        title: "账户类型",
                        key: "accountType",
                        minWidth: 150,
                        slot:"accountType",
                    },
                    {
                        title: "开户行省份",
                        key: "openingBankProvince",
                        minWidth: 150,
                        slot:"openingBankProvince"
                    },
                    {
                        title: "开户行城市",
                        key: "openingBankCity",
                        minWidth: 150,
                        slot:"openingBankCity"
                    },
                    {
                        title: "状态",
                        key: "status",
                        minWidth: 140,
                        slot:"status"

                    },
                    {
                        title: "操作",
                        key: "action",
                        minWidth: 200,
                        align: "center",
                        fixed: "right",
                        slot: "action"
                    }
                ],
                data: [],
                total: 0
            };
        },
        props:{
            isNewCarRole:{
                type:String,
            },
            isOldCarRole:{
                type:String,
            }
        },
        methods: {
            init() {
                this.getProvinceData();
                this.getCityData();
                this.getLocationData();
                this.initLabelType();
            },
            changePage(v) {
                this.accountForm.pageNumber = v;
                this.getList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.accountForm.pageSize = v;
                this.getList();
            },
            getList() {
                // 根据id查询收款账号信息
                let channelId = this.$parent.channelId;
                this.accountForm.channelId=channelId;
                if(channelId ==null || channelId=="" || channelId==undefined){
                    this.loading = false;
                    return;
                }
                getListData(this.accountForm).then(res => {
                    if (res.code === "0000") {
                        this.data = res.data.records;
                        this.total = res.data.total;
                    }
                });
            },
            getAccountInfo(v) {
                //根据id查询收款账号信息
                let channelId = v;
                this.accountForm.channelId=channelId;

                getListData(this.accountForm).then(res => {
                    if (res.code === "0000") {
                        this.data = res.data.records;
                        this.total = res.data.total;
                    }
                });

                getChannelBaseInfo(v).then(res => {
                    if (res.code === "0000") {
                        let str = JSON.stringify(res.data[0]);
                        let channelBaseInfoTemp = JSON.parse(str);
                        this.invoiceForm.id=res.data[0].id;
                        this.invoiceForm.channelStatus=res.data[0].channelStatus;
                        this.invoiceForm.taxpayerType=channelBaseInfoTemp.taxpayerType;
                        this.invoiceForm.taxpayerIdNumber=channelBaseInfoTemp.taxpayerIdNumber;
                        this.invoiceForm.invoiceTelNumber=channelBaseInfoTemp.invoiceTelNumber;
                        this.invoiceForm.invoiceAddress=channelBaseInfoTemp.invoiceAddress;
                        this.invoiceForm.openingBank=channelBaseInfoTemp.openingBank;
                        this.invoiceForm.bankAccount=channelBaseInfoTemp.bankAccount;
                        this.invoiceForm.taxRate=channelBaseInfoTemp.taxRate;
                    }
                });
            },



            handleSearch() {
                this.accountForm.pageNumber = 1;
                this.accountForm.pageSize = 10;
                this.getList();
            },
            handleReset() {
                this.$refs.accountForm.resetFields();
                this.accountForm.pageNumber = 1;
                this.accountForm.pageSize = 10;
                // 重新加载数据
                this.getList();
            },
            changeSort(e) {
                this.accountForm.sort = e.key;
                this.accountForm.order = e.order;
                if (e.order === "normal") {
                    this.accountForm.order = "";
                }
                this.getList();
            },
            cancelAccount() {
                //关闭窗口
                this.channelModalVisible = false;
            },
            saveAccount(){
                console.log("收款账户信息保存开始！");
                let channelId = this.$parent.channelId
                if (channelId == "" || channelId == undefined) {
                    this.$Message.error("请先保存基本信息");
                    return;
                }
                let openingBankProvince = this.channelForm.openingBankValue[0];
                let openingBankCity = this.channelForm.openingBankValue[1];
                this.$refs.channelForm.validate(valid => {
                    if (valid) {
                        if (this.modalType === 0) {
                            var params = {
                                //收款账号信息
                                channelReceivablesAccountTemp: {
                                    channelId:this.$parent.channelId,
                                    accountType: this.channelForm.accountType,
                                    receivingName: this.channelForm.receivingName.replace(/\s*/g,""),
                                    receivingAccount: this.channelForm.receivingAccount,
                                    receivingBank: this.channelForm.receivingBank,
                                    receivingSubBranch: this.channelForm.receivingSubBranch.replace(/\s*/g,""),
                                    electronicBankNo: this.channelForm.electronicBankNo,
                                    receivingMobilePhone: this.channelForm.receivingMobilePhone,
                                    receivingMailAddress: this.channelForm.receivingMailAddress,
                                    receivingRemarks: this.channelForm.receivingRemarks,
                                    accountAttribute:this.channelForm.accountAttribute,
                                    collectionType:this.channelForm.collectionType,
                                    openingBankProvince:openingBankProvince,
                                    openingBankCity:openingBankCity,
                                    status:"02",
                                },
                            }
                            //收款账号信息
                            saveAccountInfo(params).then(res => {
                                if (res.code === "0000") {
                                    this.$Message.success("保存成功");
                                    this.channelModalVisible = false;
                                    this.getList();
                                }
                            }).catch(() => {
                                this.submitLoading = false;
                            });
                        }else{
                            //收款账号信息修改
                            this.channelForm.openingBankProvince=openingBankProvince;
                            this.channelForm.openingBankCity=openingBankCity;
                            this.channelForm.channelId=this.$parent.channelId;
                            updateAccountInfo(this.channelForm).then(res => {
                                if (res.code === "0000") {
                                    this.$Message.success("保存成功");
                                    this.channelModalVisible = false;
                                    this.getList();
                                }
                            }).catch(() => {
                                this.submitLoading = false;
                            });
                        }
                    }
                });
            },
            invoiceSave(){
                console.log("发票信息保存开始！");
                console.log(this.$refs.invoiceForm)
            //    this.$refs.invoiceForm.validate(valid => {
                //    if (valid) {
                    let param = {
                        //开票信息
                        id:this.$parent.channelId,
                        taxpayerType: this.invoiceForm.taxpayerType,
                        taxpayerIdNumber: this.invoiceForm.taxpayerIdNumber,
                        invoiceTelNumber: this.invoiceForm.invoiceTelNumber,
                        invoiceAddress: this.invoiceForm.invoiceAddress,
                        openingBank: this.invoiceForm.openingBank,
                        bankAccount: this.invoiceForm.bankAccount,
                        taxRate: this.invoiceForm.taxRate,
                    }

                        console.log("发票信息保存999！");
                        //保存发票信息
                        savaInvoiceInfo(param).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("保存成功");
                                this.invoiceForm =res.data(0);
                                this.getList();
                            }
                        }).catch(() => {
                            this.submitLoading = false;
                        });
                //    }
             //   });
            },
            invoiceSubmit(){
                console.log("发票信息提交开始！");
             //   this.$refs.invoiceForm.validate(valid => {
                  //  if (valid) {
                        let param = {
                            //开票信息
                            id:this.$parent.channelId,
                            taxpayerType: this.invoiceForm.taxpayerType,
                            taxpayerIdNumber: this.invoiceForm.taxpayerIdNumber,
                            invoiceTelNumber: this.invoiceForm.invoiceTelNumber,
                            invoiceAddress: this.invoiceForm.invoiceAddress,
                            openingBank: this.invoiceForm.openingBank,
                            bankAccount: this.invoiceForm.bankAccount,
                            taxRate: this.invoiceForm.taxRate,
                        }
                        //保存发票信息
                        savaInvoiceInfo(param).then(res => {
                            if (res.code === "0000") {
                               //调用基础页面的提交方法,并把收款账号提交上去
                                //修改收款信息的状态 改成启用
                                this.$parent.useBasicSubmitToCase();
                                /*changeAccountStatus(this.$parent.channelId).then(res => {
                                    if (res.code === "0000") {

                                        this.getList();
                                    }
                                })*/
                            }
                        }).catch(() => {
                            this.submitLoading = false;
                        });

                //    }
              //  });
            },
            add() {
                this.modalType = 0;
                this.modalTitle = "收款账号信息新增";
                this.$refs.channelForm.resetFields();
                this.channelModalVisible = true;
                if(this.newCarRole=="1" && this.oldCarRole=="1"){
                    this.accountAttributeDisabled=false;
                }else if(this.newCarRole=="1"){
                    this.channelForm.accountAttribute="01";
                    this.accountAttributeDisabled=true;
                }else{
                    this.channelForm.accountAttribute="02";
                    this.accountAttributeDisabled=true;
                }
            },

            edit(e) {
                /*if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择要修改的数据");
                    return;
                }
                if (this.selectCount >1) {
                    this.$Message.warning("请逐条进行修改");
                    return;
                }*/
                this.modalType = 1;
                this.modalTitle = "收款账号编辑";
                this.$refs.channelForm.resetFields();
                if(this.newCarRole=="1" && this.oldCarRole=="1"){
                    this.accountAttributeDisabled=false;
                }else if(this.newCarRole=="1"){
                    this.channelForm.accountAttribute="01";
                    this.accountAttributeDisabled=true;
                }else{
                    this.channelForm.accountAttribute="02";
                    this.accountAttributeDisabled=true;
                }

                let id ="";
                let receivingName="";
                let accountAttribute="";
                let accountType="";
                let collectionType="";
                let receivingAccount="";
                let receivingBank="";
                let receivingSubBranch="";
                let electronicBankNo="";
                let receivingMobilePhone="";
                let receivingMailAddress="";
                let receivingRemarks="";
                let openingBankProvince="";
                let openingBankCity="";
               // this.selectList.forEach(function (e) {
                    id += e.id;
                    receivingName=e.receivingName;
                    accountAttribute=e.accountAttribute;
                    accountType=e.accountType;
                    collectionType=e.collectionType;
                    receivingAccount=e.receivingAccount;
                    receivingBank=e.receivingBank;
                    receivingSubBranch=e.receivingSubBranch;
                    electronicBankNo=e.electronicBankNo;
                    receivingMobilePhone=e.receivingMobilePhone;
                    receivingMailAddress=e.receivingMailAddress;
                    receivingRemarks=e.receivingRemarks;
                    openingBankProvince=e.openingBankProvince;
                    openingBankCity=e.openingBankCity;
            //    });
                this.channelForm.receivingName=receivingName;
                this.channelForm.id=id;
                this.channelForm.accountAttribute=accountAttribute;
                this.channelForm.accountType=accountType;
                this.channelForm.collectionType=collectionType;
                this.channelForm.receivingAccount=receivingAccount;
                this.channelForm.receivingBank=receivingBank;
                this.channelForm.receivingSubBranch=receivingSubBranch;
                this.channelForm.electronicBankNo=electronicBankNo;
                this.channelForm.receivingMobilePhone=receivingMobilePhone;
                this.channelForm.receivingMailAddress=receivingMailAddress;
                this.channelForm.receivingRemarks=receivingRemarks;
                let openingBankValue = [];
                if(openingBankProvince!=null && openingBankProvince !="" && openingBankProvince !=undefined){
                    openingBankValue[0]=openingBankProvince;
                    openingBankValue[1]=openingBankCity;
                }
                this.channelForm.openingBankValue=openingBankValue;
                this.channelModalVisible = true;
            },

            remove(v) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除 " + v.receivingName + " ?",
                    onOk: () => {
                        this.operationLoading = true;
                        deleteAccount(v.id).then(res => {
                            this.operationLoading = false;
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.getList();
                            }
                        });
                    }
                });
            },

            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            //地址公共信息调用
            locationChange(item, callback) {
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            },
            //选择是否默认邮寄账号
            selectRadio(value){
                //this.defaultAccount=value;
            },
            readOnlyInfo(b) {
                let _this=this;
                this.$nextTick(()=>{
                    _this.typeCode=b;
                })
            },
            getOpeningBankProvince(openingBankProvince){
                if(openingBankProvince!=""){
                    let province="";
                    for(let i=0;i<this.province.length;i++){
                        if(this.province[i].value==openingBankProvince){
                            province=this.province[i].label;
                        }
                    };
                    return province;
                }else{
                    return '';
                }
            },
            getOpeningBankCity(openingBankCity){
                if(openingBankCity!=""){
                    let city="";
                    for(let i=0;i<this.city.length;i++){
                        if(this.city[i].value==openingBankCity){
                            city=this.city[i].label;
                        }
                    };
                    return city;
                }else{
                    return '';
                }
            },
            getProvinceData() {
                let param = {Level: "1", upperCode: "1"};
                getLocation(param).then(res => {
                    if (res.code == "0000") {
                        this.province=res.data;
                    }
                });
            },
            getCityData() {
                let param = {Level: "2", upperCode: ""};
                getLocation(param).then(res => {
                    if (res.code == "0000") {
                        this.city=res.data;
                    }
                });
            },

            //收款类型
            setCollectionTypeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.collectionTypeList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            //账号类型
            setAccountTypeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.accountTypeList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },
            initLabelType(){
                let collectionTypeDic="collectionType";
                getDictDataByType(collectionTypeDic).then(res =>{
                    if (res.code === "0000"){
                        this.collectionTypeList = res.data;
                    }
                });

                let accountTypeDic="accountType";
                getDictDataByType(accountTypeDic).then(res =>{
                    if (res.code === "0000"){
                        this.accountTypeList = res.data;
                    }
                });

                let receivingBankDic="bank";
                getDictDataByType(receivingBankDic).then(res =>{
                    if (res.code === "0000"){
                        this.receivingBankList = res.data;
                    }
                });

                let accountAttributeDic="businessType";
                getDictDataByType(accountAttributeDic).then(res =>{
                    if (res.code === "0000"){
                        this.accountAttributeList = res.data;
                    }
                });
            },

            //银行名称
            setReceivingBankTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.receivingBankList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },

            //账号属性
            setAccountAttributeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                this.accountAttributeList.forEach(column => {
                    if(column.value === val){
                        dic = column;
                    }
                });
                return dic.title;
            },


        },
        mounted() {
            this.init();
            let _this=this;
            vueEvent.$on('to-directCardealerAccountInfo',function(param){
                console.log(param);
                _this.newCarRole=param.newCarRole;
                _this.oldCarRole=param.oldCarRole;
                console.log(_this.newCarRole,"新车",_this);
                console.log(_this.oldCarRole,"二手车");
            });
        }
    };
</script>
